export default {
    methods: {
        createShader(gl, type, source) {
            let shader= gl.createShader(type);
            gl.shaderSource(shader, source);
            gl.compileShader(shader);
            let success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
            if (success) return shader;
            console.log(gl.getShaderInfoLog(shader));
            gl.deleteShader(shader);
        },
        createProgram(gl, vertexShader, fragmentShader) {
            let program = gl.createProgram();
            gl.attachShader(program, vertexShader);
            gl.attachShader(program, fragmentShader);
            gl.linkProgram(program);
            let success = gl.getProgramParameter(program, gl.LINK_STATUS);
            if (success) return program;
            console.log(gl.getProgramInfoLog(program));
            gl.deleteProgram(program);
        },
        resizeCanvasToDisplaySize(canvas, multiplier) {
            multiplier = multiplier || 1;
            const width = canvas.clientWidth * multiplier | 0;
            const height = canvas.clientHeight * multiplier | 0;
            if (canvas.width !== width || canvas.height !== height) {
                canvas.width = width;
                canvas.height = height;
                return true;
            }
            return false;
        }
    }
}